package ru.passivemoney.aspect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public aspect LoggingAspect {
	
	private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
	
	public pointcut methodInExitPointcat() :
		execution(* ru.passivemoney..*.*(..))
		&& !within(LoggingAspect)
		&& !execution(* *.toString());
	
	Object around() : methodInExitPointcat(){
		logger.debug("Start method {}", thisJoinPointStaticPart.getSignature());
		if(logger.isTraceEnabled()){
			if(thisJoinPoint.getTarget() != null){
				logger.trace("\tTarget object: [{}]", thisJoinPoint.getTarget());
			}
			int argumentCount = 1;
			for(Object o : thisJoinPoint.getArgs()){
				logger.trace("\t{} argument: [{}]", argumentCount++, o);
			}
		}
		
		Object out;
		try{
			out = proceed();
		}finally{
			logger.debug("Exit method {}", thisJoinPointStaticPart.getSignature());
		}
		return out;
	}
}
